package com.mesmileAI.controller;

import com.mesmileAI.entity.SmlieIndex;
import com.mesmileAI.service.SmlieIndexService;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 文本模型接口
 *
 * <p>
 * --------------------
 *
 * @author  Alexis
 * @since 2020-02-19
 */

@RestController
@AllArgsConstructor
@Slf4j
@RequestMapping("/indexPrompt")
public class SmileIndexController {

    @Resource
    SmlieIndexService service;


    /**
     * 详情
     */
    @GetMapping("/detail/{id}")
    public SmlieIndex detail(@PathVariable String id) {
        SmlieIndex detail=service.getById(id);
        //查询用户角色
        if (detail == null) {
            SmlieIndex smlieIndex =new SmlieIndex();
            smlieIndex.setId("500");
            return smlieIndex ;
        }
        return detail ;
    }


    //输出所有的提示词
    @GetMapping("/list")
    public List<SmlieIndex> list(){
        return service.list();
    }

    //新增所有的提示词
    @PutMapping ("/save")
    public boolean save(@RequestBody SmlieIndex smlieIndex){
        try {
            Date date = new Date();
            smlieIndex.setCreateTime(date);
            service.save(smlieIndex);
        }catch (Exception e){
            return false;
        }
        return true;
    }

    //修改提示词
    @PostMapping("/update")
    public Boolean update(@RequestBody SmlieIndex smlieIndex){
        try {
            Date date = new Date();
            smlieIndex.setCreateTime(date);
            service.updateById(smlieIndex);
        }catch (Exception e){
            return false;
        }
        return true;
    }

    //删除提示词
    @DeleteMapping("/delete/{id}")
    public Boolean delete(@PathVariable String id){
        try {
            service.removeById(id);
        }catch (Exception e){
            return false;
        }
        return true;
    }


}
